package com.example.administrator.yanfoxconn.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.activity.KHMainListActivity;
import com.example.administrator.yanfoxconn.bean.KHInfo;


import java.util.List;

import androidx.annotation.RequiresApi;

/**
 * @Description
 * @Author song
 * @Date 9/24/21 10:39 AM
 */
public class KHHeadListAdapter extends BaseAdapter {

    private KHMainListActivity activity;
    private List<KHInfo> listMessages;
    private String status;

    private OnClickListenerFour onClickListenerFour;

    public KHHeadListAdapter(KHMainListActivity activity, List<KHInfo> listMessages){
        this.activity = activity;
        this.listMessages = listMessages;
    }

    @Override
    public int getCount() {
            return listMessages.size();
    }

    @Override
    public Object getItem(int position) {
            return listMessages.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @SuppressLint("ResourceAsColor")
    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            Log.e("===", "ss");
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_kh_item, null);

                holder.tvId = (TextView) convertView.findViewById(R.id.tv_id);
                holder.tvType = (TextView) convertView.findViewById(R.id.tv_type);
                holder.tvNum = (TextView) convertView.findViewById(R.id.tv_num);
                holder.tvEmpNo = (TextView) convertView.findViewById(R.id.tv_emp_name);
                holder.tvStatue = convertView.findViewById(R.id.tv_statue);//放行
                holder.tvAdd = convertView.findViewById(R.id.tv_up_photo);//上傳
                holder.tvSee = convertView.findViewById(R.id.tv_see);//瀏覽
                holder.tvDel = convertView.findViewById(R.id.tv_del);//刪除
                holder.tvAdd = convertView.findViewById(R.id.tv_add);//增加
                holder.tvDone = convertView.findViewById(R.id.tv_Done);//確認

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


            holder.tvId.setText(listMessages.get(position).getI_ID());
            holder.tvType.setText(listMessages.get(position).getI_TYPE());
            holder.tvNum.setText((position+1)+"");
        holder.tvEmpNo.setText(listMessages.get(position).getI_EMPNAME());
        holder.tvStatue.setText(listMessages.get(position).getI_STATUS());
            status = listMessages.get(position).getI_STATUS();

            if (status.equals("訪談中")) {
                holder.tvStatue.setBackgroundResource(R.color.color_fee123);
            }else if (status.equals("處理中")){
                holder.tvStatue.setBackgroundResource(R.color.main_color);
            }else if (status.equals("已結案")){
                holder.tvStatue.setBackgroundResource(R.color.color_42D42B);
            }

            holder.tvSee.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onClickListenerFour != null) {
                        onClickListenerFour.OnClickListenerSee(position);
                    }
                }
            });
            holder.tvDel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onClickListenerFour != null) {
                        onClickListenerFour.OnClickListenerDel(position);
                    }
                }
            });
        holder.tvAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerFour != null) {
                    onClickListenerFour.OnClickListenerAdd(position);
                }
            }
        });
        holder.tvDone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerFour != null) {
                    onClickListenerFour.OnClickListenerDone(position);
                }
            }
        });

        return convertView;
    }


    private class ViewHolder {
        public TextView  tvSee, tvDel, tvAdd,tvDone;//瀏覽，刪除，增加，確認
        public TextView tvNum,tvId,tvType,tvStatue,tvEmpNo;//序號，單號，訪談類型，狀態，訪談人

    }
    public interface OnClickListenerFour {
        void OnClickListenerSee(int position);
        void OnClickListenerDel(int position);
        void OnClickListenerAdd(int position);
        void OnClickListenerDone(int position);
    }

    public void setOnClickListenerFour(OnClickListenerFour onClickListenerFour) {
        this.onClickListenerFour = onClickListenerFour;
    }
}
